//
//  MyToolsClass.m
//  myyouling
//
//  Created by hunuo on 15/9/24.
//  Copyright (c) 2015年 hunuo. All rights reserved.
//

#import "MyToolsClass.h"
#define SYS_VER [UIDevice currentDevice].systemVersion.floatValue
@implementation MyToolsClass

+ (UIButton *)createBtnWithFrame:(CGRect)rect title:(NSString *)title image:(UIImage *)image target:(id)target action:(SEL)action
{
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = rect;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setBackgroundImage:image forState:UIControlStateNormal];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return btn;
}

+ (UILabel *)createLbWithFrame:(CGRect)rect title:(NSString *)title aliment:(NSTextAlignment)aliment color:(UIColor *)color size:(CGFloat)size
{
    UILabel * lb = [[UILabel alloc] initWithFrame:rect];
    lb.text = title;
    lb.textAlignment = aliment;
    lb.textColor = color;
    lb.font = [UIFont systemFontOfSize:size];
    return lb;
}

+ (CGSize)caculateText:(NSString *)str fontSize:(CGFloat)size maxSize:(CGSize)maxSize
{
    UIFont * font = [UIFont systemFontOfSize:size];
    if (SYS_VER >= 7.0) {
        return [str boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size;
    }else{
        return [str sizeWithFont:font constrainedToSize:maxSize];
    }
}


@end
